<?php
/*
 * (C) Copyright 2013 Torsten Gorath (http://www.blauesdach.de/).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Contributors:
 *     Torsten Gorath
 */
require_once $basedir."/inc/gruppen.php";
$gruppe = new Gruppen();
if(isset($_REQUEST['id']) && $_REQUEST['id']!="") {
	$gruppe = new Gruppen($_REQUEST['id']);
}
if(isset($_REQUEST['save'])) {
	$gruppe->setName($_REQUEST['name']);
	$gruppe->setPlaetze($_REQUEST['plaetze']);
	$gruppe->setFoerderung($_REQUEST['foerderung']);
	$gruppe->save();
}
?>
<?php
if($action=='edit') {
	$action = 'add';
}
if($action=='add') {
	$form_display = "block";
} else {
	$form_display = "none";
}
?>
<form id='stammdaten_gruppen_add_form' method="post" action="/index.php" style='display:<?php echo $form_display; ?>'>
	<input type="hidden" name="page" value="<?php echo $menuid;?>" />
	<input type="hidden" name="id" value="<?php echo $gruppe->getId(); ?>" />
    <div>
    	<div class='inline-block label'>Name:</div>
    	<div class='inline-block'>
	        <input type="text" name="name" maxlength="50" value="<?php echo $gruppe->getName(); ?>" /><br />
    	</div>
    </div>
    <div>
    	<div class='inline-block label'>Anzahl Pl&aumltze:</div>
    	<div class='inline-block'>
	        <input type="number" name="plaetze" maxlength="10" value="<?php echo $gruppe->getPlaetze(); ?>" /><br />
    	</div>
    </div>
    <div>
    	<div class='inline-block label'>F&ouml;rderrung:</div>
    	<div class='inline-block'>
    		<select name='foerderung'>
    			<option value='Keine' <?php echo $gruppe->getFoerderung()=="Keine"?"selected='true'":""; ?>>Keine</option>
    			<option value='Foerdervertrag' <?php echo $gruppe->getFoerderung()=="Foerdervertrag"?"selected='true'":""; ?>>F&ouml;rdervertrag</option>
    			<option value='Spielkreis' <?php echo $gruppe->getFoerderung()=="Spielkreis"?"selected='true'":""; ?>>Spielkreis</option>    			
    		</select>
    	</div>
    </div>
    <div>
        <button type="submit" name="save">Speichern</button>
        <button type="submit" name="reset">Abbrechen</button>
    </div>
</form>
<?php
if($action!="add") {
	$gruppen = Gruppen::getAll();
?>
<div>
    <a href='?page=<?php echo $menuid;?>&action=add'>Neue Gruppe</a>
</div>
<div>
    <table border="1" bordercolor="black" cellpadding="0" cellspacing="0" >
        <tr>
        	<th></th>
            <th>Name</th>
            <th>Pl&auml;tze</th>
            <th>F&ouml;rderung</th>
            <th></th>
        </tr>
<?php
if($gruppen!=NULL) {
	for($i=0;$i<count($gruppen);$i++) {
		$value = $gruppen[$i];
		$css_class = "even";
		if($i%2==1) {
			$css_class = "odd";
		}
?>
		<tr class="<?php echo $css_class; ?>">
			<td><?php echo ($i+1); ?></td>
			<td><?php echo $value->getName();?></td>
			<td><?php echo $value->getPlaetze();?></td>
			<td><?php echo $value->getFoerderung();?></td>
			<td><a href="?page=<?php echo $menuid; ?>&action=edit&id=<?php echo $value->getId();?>">edit</a></td>
		</tr>
<?php
	}
}
?>
    </table>
</div>
<?php    
}
?>